﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DAL;
public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {



    }
    protected void btnOK_Click(object sender, EventArgs e)
    {
        add();
    }


    private void add()
    {
        using (DataClassesDataContext lqDB = new DataClassesDataContext())
        {
            if (isempty() == true)
            {
                string typename = txtTypeName.Text;
                TypeInfo type = lqDB.TypeInfo.FirstOrDefault(t => t.Type_Name == typename);
                if (type == null)
                {
                    TypeInfo addtype = new TypeInfo();
                    // addtype.Type_ID = Convert.ToInt32(txtTypeID.Text);
                    addtype.Type_Name = txtTypeName.Text;
                    lqDB.TypeInfo.InsertOnSubmit(addtype);
                    lqDB.SubmitChanges();
                    Frame.Global.GlobalFunctions.AlertToUrl("添加成功！", "EditProTypeInfo.aspx");
                }
                else
                {
                    Frame.Global.GlobalFunctions.Alert("对不起！您添加的项目类型已经存在！");
                }
            }
        }
    }
    private bool isempty()
    {
        bool isempty = true;
        if (txtTypeName.Text.Equals(""))
        {
            Frame.Global.GlobalFunctions.Alert("项目类型名称不能为空!");
            isempty = false;
        }
        else
        {
            return true;
        }
        return isempty;
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("EditProTypeInfo.aspx");
    }
}